﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

namespace PeisongWeb.admin
{
    public partial class webNewsEdit : adminPage
    {
        protected int id
        {
            get
            {
                int tmp;
                try { tmp = Convert.ToInt32(ViewState["id"]); }
                catch { tmp = 0; }
                return tmp;
            }
            set
            {
                ViewState["id"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("AG", 2))
                {
                    if (Request.QueryString["id"] != null)
                    {
                        if (Library.Number.IsIntPositive(Request.QueryString["id"]))
                        {
                            id = Convert.ToInt32(Request.QueryString["id"]);
                        }
                    }
                    if (id!=0)
	                {                    
                        getDetails();
		 
                    }

                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        private void getDetails()
        {
            WebNewsEntity wn = logic.webNews.getById(id);
            txtContent.Text = wn.Text;
            txtUrl.Text = wn.Url;
            chkIsShow.Checked = wn.IsShow;
        }
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            WebNewsEntity wn = new WebNewsEntity();
            wn.Url = txtUrl.Text;
            wn.IsShow = chkIsShow.Checked;
            wn.Text = txtContent.Text;
            if (id != 0)
            {
                wn.Id = id;
                logic.webNews.update(wn);
            }
            else
            {
                wn.AdminId = logic.sysAdmin.AdminID;
                logic.webNews.insert(wn);
            }
            Library.Script.ClientMsgUrl("保存成功！", "webNewsList.aspx");
        }
    }
}
